﻿#ifndef			_LIBINI_SECTION_H_
#define			_LIBINI_SECTION_H_


#include <libini/header.h>
#include <libini/explain.h>
#include <libini/item.h>


namespace Xanadu::ini
{
	class LIBINI_EXPORT section
	{
	private:
		// Comments for row data
		std::list<Xanadu::ini::explain>				_memberComment;

		// The name of the section
		std::string 						_memberName;

		// Subitem list
		std::map<std::string, Xanadu::ini::item>		_memberItems;

	public:
		// constructor
		explicit section() noexcept;

		// constructor
		explicit section(const std::string& _String) noexcept;

		// constructor
		section(const Xanadu::ini::section& _Other) noexcept;

		// destructor
		virtual ~section() noexcept;

	public:
		// operator overload =
		Xanadu::ini::section& operator = (const Xanadu::ini::section& _Other) noexcept;

	public:
		// Set the data for the section
		virtual void setData(const std::string& _String) noexcept final;

		// Set the data for the section
		virtual void setData(const char* _Bytes, std::size_t _Length) noexcept final;

	public:
		// Get comment
		virtual std::string comment() const noexcept;

		// Get section name
		virtual std::string name() const noexcept;

	public:
		// Set comment
		virtual void setComment(const std::string& _Comment) noexcept;

		// Set section name
		virtual void setName(const std::string& _Name) noexcept;

	public:
		// Find key value
		virtual Xanadu::ini::item& find(const std::string& _Key) noexcept;

		// Find key value
		virtual const Xanadu::ini::item& find(const std::string& _Key) const noexcept;

		// Find key value
		virtual bool find(const std::string& _Key, Xanadu::ini::item& _Item) const noexcept;

		// Set key value
		virtual void set(const std::string& _Key, const std::string& _Value) noexcept;

		// Remove line
		virtual void remove(const std::string& _Key) noexcept;

	public:
		// Convert to string
		virtual std::string toString() const noexcept;

		// Format from one or more lines of strings
		static Xanadu::ini::section fromStrings(const std::list<std::string>& _Strings) noexcept;

	private:
		// Analysis section, returns all key value
		static std::list<std::list<std::string>> split_item(const std::list<std::string>& _Strings) noexcept;
	};
}

#endif
